Make a plotly object from scratch:
library(plotly)
## Warning: package 'plotly' was built under R version 3.3.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.3.2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
plot_ly(d, x = ~carat, y = ~price, color = ~carat,
size = ~carat, text = ~paste("Clarity: ", clarity))
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plot.ly/r/reference/#scatter
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
Make a ggplot object from scratch:
library(ggplot2)
library(viridis)
my_plot <- ggplot(diamonds,
aes(x = carat, y = price, color = color)) +
scale_color_viridis(discrete = TRUE) +
geom_point() +
facet_grid(cut ~ clarity) +
theme_bw()
print(my_plot)
Send the ggplot object into plotly:
ggplotly(my_plot)